package com.zhisheng.day10_tlias.service.impl;

import com.zhisheng.day10_tlias.entry.DeptLog;
import com.zhisheng.day10_tlias.mapper.DeptLogMapper;
import com.zhisheng.day10_tlias.service.DeptLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDateTime;

@Service
public class DeptLogServiceImpl implements DeptLogService {

    @Autowired
    private DeptLogMapper deptLogMapper;

    // 这个业务层负责封装了一个对象,并交给自己的 mapper 层添加到数据库
    @Override
    @Transactional(propagation = Propagation.REQUIRES_NEW)  // 确保无论调用者是否提交事务,我们这个方法都是一个独立的事务
    public int insertDeptLog(String desc) {
        DeptLog deptLog = new DeptLog(null,LocalDateTime.now(),desc);
        return deptLogMapper.insertDeptLog(deptLog);
    }
}
